
local unit_attribute = require 'types.unit_attribute'
local register = unit_attribute.register

register('刷新次数')
register('抽卡次数',{
    set = function(self)
        self:notify('单位-抽卡次数变动',self)
    end
})

--费用初始/增加/最大
local mt = ac.skill['抽取天赋']
mt.title = '抽取卡牌'
mt.art = [[ReplaceableTextures\CommandButtons\BTNSkillz.blp]]
mt.tip = [[消耗木头抽取卡牌，获取卡牌后直接吞噬]]
mt.is_order = 1
mt.slotid = 8
mt.show_num = 0
--mt.hotkey = 'F'
mt.resume_flag = true
mt.count = 0

function mt:get_lum()
    local hero = self.owner
    return math.min(100 + self.count * 10, 200)
end

function mt:on_add()
    local hero = self.owner
    local player = hero.owner
    self:gc(ac.loop(100,function()
        self.show_effect = player:get('木材')>=self:get_lum()
    end))
end

function mt:on_cast_shot()
    local hero = self.owner
    local player = hero.owner
    local show = player:get_data('天赋选择表')
    local lum = self:get_lum()
    if player._tf_ani_timer then
        return
    end
    if show then
        player:notify('玩家-显示抽卡',player,show)
        return
    end
    if player:get('木材')<lum then
        show_skill_tip(player,self.slotid,'木材')
        return
    end
    self.count = self.count + 1
    player:add('木材',-lum)
    player:notify('玩家-抽取天赋',player)
    player:notify('引导-显示内容',player)
    player:set_data('引导-卡牌羁绊',true)
end

ac.sync:event '玩家-刷新抽卡'(function(_,player)
    local xd = player:get_data('刷新次数',0)*200 + 200
    if player:get('杀敌')<xd then
        show_ui_effect(player,1920/2,750,'杀敌')
        return
    end
    player:set_data('刷新次数',player:get_data('刷新次数',0) + 1)
    player:add('杀敌',-xd)
    player:notify('玩家-抽取天赋',player)
end)

ac.game:event '玩家-选择英雄完毕'(function(_,player,hero)
    hero:add_skill('抽取天赋','英雄')
end)